package com.yzy.soft.system.freemarker.template;

import com.yzy.soft.system.freemarker.*;
import com.yzy.soft.system.freemarker.database.Table;
import com.yzy.soft.system.freemarker.database.Column;
import com.yzy.soft.system.freemarker.database.PrimaryKey;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class TemplateModel  extends TemplateKernel {

    private final static Logger logger=LoggerFactory.getLogger(TemplateModel.class);



    private List<Column> columnsInfo;

    private List<PrimaryKey> primaryKeysInfo;


    @Override
    public File generateFileType(FileInfo fileInfo,Table table, DBInfo dbInfo) throws Exception {
        //JdbcUtil jdbcUtil=new JdbcUtil(dbInfo.getDriver(),dbInfo.getUrl(),dbInfo.getUsername(),dbInfo.getPassword());

        JavaFileModel javaFile=((JavaFile)fileInfo).getJavaFileModel();
        String tableName = javaFile.getFilename();
        final String path = fileInfo.getDiskPath() + tableName + javaFile.getSuffix();
        logger.info("TemplateModel path:"+path);
        final String templateName = "Model.ftl";

        File file = new File(path);
        Map<String, Object> dataMap = new HashMap<String, Object>();
        dataMap.put("model_column", table.getColumns());
        dataMap.put("table_name", tableName);
        dataMap.put("table_name_small", tableName);
        dataMap.put("package_name", javaFile.getPackageName());
//        dataMap.put("project_name", fileInfo.getproject_name);
        generateFileByTemplate(templateName, file,fileInfo, dataMap);
        return file;
    }
}
